package ru.papergames.model.proxies
{
	import mx.rpc.events.ResultEvent;
	
	import org.puremvc.as3.interfaces.IFacade;
	
	import ru.papergames.model.proxies.BaseResponder;

	public class MainResponder extends BaseResponder
	{
		public var mainResultFunction:Function;
		public var invokerProxy:MainHTTPProxy;
		
		public function MainResponder(facade:IFacade, resultNote:String, faultNote:String, globalCompleteNote:String=null)
		{
			super(facade, resultNote, faultNote, globalCompleteNote);
		}
		
		override public function result(data:Object):void {
			var result:ResultEvent = data as ResultEvent;
			
			if (resultFunction is Function) {
				var response:XML = result.result as XML; 
				
				//validate response format
				
				if (response && mainResultFunction is Function) {					
					mainResultFunction(response, invokerProxy);									
				} 
				
			}
			
			super.result(data);
		}
		
		override protected function finish():void {
			super.finish();
			mainResultFunction = null;
			invokerProxy = null;
		}
		
	}
}